﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using System.IO;

namespace TS_XY_Train_Repaire.UserCon.Main_Base
{
    public partial class uc_Main_Base_CheckPDF : DevExpress.XtraEditors.XtraForm
    {
        public uc_Main_Base_CheckPDF()
        {
            InitializeComponent();
        }

        public static string fid;
        private void uc_Main_Base_CheckPDF_Load(object sender, EventArgs e)
        {
            if (!Directory.Exists(TS_Win_Class._EXP_Direct))
            {

                Directory.CreateDirectory(TS_Win_Class._EXP_Direct);

            }
            if (File.Exists(TS_Win_Class._EXP_Direct + "Temp.pdf"))
            {
                File.Delete(TS_Win_Class._EXP_Direct + "Temp.pdf");
            }
            System.Data.DataTable dt = TS_Win_Class.GetFilledDataTable("select top 1 * from TS_S_T_P_Tree_Resource where f_del=0 and f_mainid= " + fid);
            string file = dt.Rows[0]["f_brief"].ToString();
            byte[] byteTo = Convert.FromBase64String(file);
            string mTransRtf = System.Text.Encoding.Default.GetString(byteTo);
            string fileName = "";
            fileName = TS_Win_Class._EXP_Direct + "Temp.pdf";
            System.IO.MemoryStream stream = new System.IO.MemoryStream(byteTo);
            FileStream fs = new FileStream(fileName, FileMode.CreateNew);
            BinaryWriter bw = new BinaryWriter(fs);

            bw.Write(byteTo, 0, byteTo.Length);
            bw.Close();
            fs.Close();

            PDF_Main.LoadFile(TS_Win_Class._EXP_Direct + "Temp.pdf");
        }
    }
}